﻿using System;
using System.Diagnostics.Contracts;
using System.Net.Sockets;

namespace Server.EventHandlers
{
    /// <summary>
    /// Provides data for a <see cref="T:System.Net.Sockets.TcpClient" /> related event.
    /// </summary>
    public sealed class TcpClientEventArgs : EventArgs
    {
        #region Fields

        /// <summary>
        /// The <see cref="T:System.Net.Sockets.TcpClient" /> related to the event.
        /// </summary>
        private readonly TcpClient m_tcpClient;

        #endregion

        #region Properties

        /// <summary>
        /// Gets the <see cref="T:System.Net.Sockets.TcpClient" /> related to the event.
        /// </summary>
        public TcpClient TcpClient
        {
            get
            {
                Contract.Ensures(Contract.Result<TcpClient>() != null);

                return m_tcpClient;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="T:Server.EventHandlers.TcpClientEventArgs" /> class.
        /// </summary>
        /// <param name="tcpClient">The <see cref="T:System.Net.Sockets.TcpClient" /> related to the event.</param>
        public TcpClientEventArgs(TcpClient tcpClient)
        {
            Contract.Requires<ArgumentNullException>(tcpClient != null);

            m_tcpClient = tcpClient;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Define the invariant valid state for this class.
        /// </summary>
        [ContractInvariantMethod]
        private void InvariantValidState()
        {
            Contract.Invariant(m_tcpClient != null);
        }

        #endregion
    }
}
